-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(core): configuration, settings and capabilities #4845
Conversation
CodSpeed Performance ReportMerging #4845 will not alter performanceComparing Summary
|
crates/biome_cli/tests/snapshots/main_commands_rage/with_configuration.snap
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a ton for this! This is a great cleanup! ❤️
Quite relieved to see the Partial
prefixes are gone now. They never sat well with me, even when I didn't see a better alternative back then. Glad to see we have a better alternative now :)
The Bool
type is also a big improvement 💪
I left a bunch of comments, mostly nits, but there's a few places where I think we should clean up a little bit more.
crates/biome_cli/tests/snapshots/main_commands_rage/with_configuration.snap
Outdated
Show resolved
Hide resolved
crates/biome_cli/tests/snapshots/main_commands_rage/with_formatter_configuration.snap
Show resolved
Hide resolved
I wouldn't do this, to be honest. Search is very much an ad-hoc action, and it's near impossible to predict how someone wants to use it. Configuring it means configuring the scope for a search while you don't yet know what you'll be searching for. I'd just leave the configuration to the CLI/LSP instead. |
True. However, some users would like not to search (or search!) some paths, like generated files, minified files, etc. |
Yeah, but I'd expect things like generated files to be part of the top-level |
Co-authored-by: Arend van Beelen jr. <[email protected]>
Co-authored-by: Arend van Beelen jr. <[email protected]>
Co-authored-by: Arend van Beelen jr. <[email protected]>
Co-authored-by: Arend van Beelen jr. <[email protected]>
Co-authored-by: Arend van Beelen jr. <[email protected]>
Co-authored-by: Arend van Beelen jr. <[email protected]>
Regarding #4845 (comment), I did more exploration. Even though In order to make things generic, we can't determine the exact types, and the compiler isn't able to infer them, so we are kind stuck. In order to make things generic, we need to kill With |
Can I have a try at it before you do that? I do like the elegance of the current solution, maybe there's another way to get it to work... |
Sure! I'll merge the PR and then we can follow up :) |
e76078c
to
e19b967
Compare
Summary
Supersedes #3317
Configuration
Partial
macro has been removed. The macro was hiding some important information, and that caused problems where some fields wereOption<T>
, and others wereT
.Option<T>
, and all fields must beOption
. As a consequence, the macro#[serde(skip_serializing_if = "Option::is_none")]
needs to be implemented for all fields. This was already done forrules
andactions
. Failing to implement the macro will result in some snapshot regressions, so we're good here and can catch bugs early.*Configuration
Bool
type that holds at build time the default value of thebool
assigned. This value is then assigned to the relative setting.bool
values functioned in our toolchain, we were forced to use methods calledis_disabled
. This is no longer an issue thanks to the newBool
type, so now we can useis_enabled
everywhere.Settings
The most significant change is how the workspace computes when whether a file is enabled for a certain feature. There are four occurrences: top-level configuration, language configuration, override top-level configuration, override language configuration. The priority is (first has most priority):
overrides.langauges.css.formatter.enabled
overrides.formatter.enabled
langauges.css.formatter.enabled
css.formatter.enabled
The main problem was that every time we needed to add a new language to the toolchain, it was very easy to miss updating the new functionality. Now, this functionality has been moved to the
ServiceLangauge
level. TheServiceLanguage
is used by the workspace to implement common functionality that must be supported by all languages. This means that we need to updateServiceLanguage
only when we add a new capability. When adding a new language, the code won't compile until all the functions of theServiceLanguage
are implemented.As you might have guessed, we would need to update the
ServiceLanguage
trait in case we add a new feature (like we did with the search). We add languages more often than features, so that's the more maintainable solution.A new method called
unwrap_settings
was created, which is used instead ofget_settings
. Why? Because the absence ofSettings
inside a project should be an error, not a possibility. Biome always createsSettings
, even whenbiome.json
isn't present. In fact, we have already raised an error (only in one occurrence) in case settings aren't found. However, I left many method signatures toOption<&Settings>
because the PR was becoming too big. I plan to that change that later.There were a lot of missing features, like assist, that weren't implemented. One more reason why implementing things at
ServiceLanguage
level should improve the internal DX of the codebase.Capabilities
enabled_for_path
, and each member of the typeEnabledForPath
checks if a certain feature (formatter, linter, assist and search) is enabled for the given path. The functions are very simple, and they are meant to call theServiceLanguage
functions viaWorkspaceSettingsHandle
. See### Settings
, first bullet point.Missing things that I will implement later
Option<&Settings>
to&Settings
WorkspaceSettingsHandle
to methods instead of&Settings
.WorkspaceSettingsHandle
is what needs to be used all over, because it's the type that is meant to hold the settings coming from the IDE.search
to the configuration (and relative sub configurations, per language), so users can configure which files can be searched or not. This isn't implemented nowadaysTest Plan
The majority of CLI tests should pass.
The rage snapshots changed, and they are fixed (you'll more
unset
).The help snapshots have been updated too.